package service;

import java.util.ArrayList;

import org.apache.ibatis.session.SqlSession;

import bean.Users;
import mapper.UsersMapper;
import util.MybatisUtil;

public class UsersServiceImpl implements UsersService {

	@Override
	public ArrayList<Users> getAllUsers() {
		
		SqlSession session = MybatisUtil.getSqlSession();
		UsersMapper mapper = session.getMapper(UsersMapper.class);
		ArrayList<Users> allUsers = mapper.getAllUsers();
		session.commit();
		return allUsers;
	}

	@Override
	public Users getOneUserByPhone(String userPhone) {

		SqlSession session = MybatisUtil.getSqlSession();
		UsersMapper mapper = session.getMapper(UsersMapper.class);
		Users userPassByPhone = mapper.getOneUserByPhone(userPhone);
		session.commit();
		return userPassByPhone;
	}
	
	@Override
	public int addOneUser(Users user)
	{
		SqlSession session = MybatisUtil.getSqlSession();
		UsersMapper mapper = session.getMapper(UsersMapper.class);
		int flag = mapper.addOneUser(user);
		session.commit();
		return flag;
		
	}
	
	@Override
	public int updatePassWord(Users user)
	{
		SqlSession session = MybatisUtil.getSqlSession();
		UsersMapper mapper = session.getMapper(UsersMapper.class);
		int flag = mapper.updatePassWord(user);
		session.commit();
		return flag;
		
	}

}
